home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / sun4c.md / bootSysAsm.s < prev    next >
Text File  |  1989-11-13  |  9KB  |  279 lines

  1. /*
  2.  * bootSysAsm.s -
  3.  *
  4.  *     Contains code that is the first executed at boot time.
  5.  *
  6.  * Copyright (C) 1985 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. .seg    "data"
  11. .asciz "$Header: /sprite/src/kernel/mach/sun4.md/RCS/bootSysAsm.s,v 1.26 89/08/09 12:34:14 mgbaker Exp Locker: mgbaker $ SPRITE (Berkeley)"
  12. .align 8
  13. .seg    "text"
  14.  
  15. #include "machConst.h"
  16. #include "machAsmDefs.h"
  17.  
  18. /*
  19.  * "Start" is used for the -e option to the loader.  "SpriteStart" is
  20.  * used for the prof module, which prepends an underscore to the name of
  21.  * global variables and therefore can't find "_start".
  22.  *
  23.  * I use a lot global registers here for start up.  Elsewhere I'm careful.
  24.  */
  25.  
  26. .align 8
  27. .seg    "text"
  28. .globl    start
  29. .globl    _spriteStart
  30. start:
  31. _spriteStart:
  32.        /* 
  33.         * Believe it or not, we're running in the middle of our stack. 
  34.     * We are placed here by the bootstrap loading which starts us
  35.     * running at 0x4000. We quickly jump out of the stack.
  36.     */
  37.     ba    realStart
  38.     nop
  39. .skip    (MACH_KERN_STACK_SIZE-0x4000)
  40. realStart:
  41.     mov    %psr, %g1
  42.     or    %g1, MACH_DISABLE_INTR, %g1    /* lock out interrupts */
  43.     andn    %g1, MACH_CWP_BITS, %g1        /* set cwp to 0 */
  44.     set    MACH_ENABLE_FPP, %g2
  45.     andn    %g1, %g2, %g1            /* disable fp unit */
  46.     mov    %g1, %psr
  47.     mov    0x2, %wim    /* set wim to window right behind us */
  48.  
  49.     /*
  50.      * The kernel has been loaded into the wrong location.
  51.      * We copy it to the right location by copying up 8 Meg worth of pmegs.
  52.      * This is done in all contexts.  8 Meg should be enough for the whole
  53.      * kernel.  We copy to the correct address, MACH_KERN_START which is
  54.      * before MACH_CODE_START, which is where we told the linker that the
  55.      * kernel would be loaded.  In this code, %g1 is segment, %g2 is
  56.      * context, %g3 is pmeg, and %g4 is offset in control space to context
  57.      * register.  %g5 contains seg size.
  58.      */
  59.     set    VMMACH_CONTEXT_OFF, %g4        /* set %g4 to context offset */
  60.     clr    %g2                /* start with context 0 */
  61.     set    VMMACH_SEG_SIZE, %g5        /* for additions */
  62. contextLoop:
  63. #ifndef sun4c
  64.     stba    %g2, [%g4] VMMACH_CONTROL_SPACE
  65. #endif
  66.     clr    %g3                /* start with 0th pmeg */
  67.     set    MACH_KERN_START, %g1        /* pick starting segment */
  68. loopStart:
  69.                     /* set segment to point to new pmeg */
  70.     stha    %g3, [%g1] VMMACH_SEG_MAP_SPACE
  71.     add    %g3, 1, %g3            /* increment which pmeg */
  72.     add    %g1, %g5, %g1            /* increment which segment */
  73.     cmp    %g3, (0x800000 / VMMACH_SEG_SIZE)    /* last pmeg? */
  74.     bne    loopStart            /* if not, continue */
  75.     nop
  76.  
  77.     add    %g2, 1, %g2            /* increment context */
  78.     cmp    %g2, VMMACH_NUM_CONTEXTS    /* last context? */
  79.     bne    contextLoop            /* if not, continue */
  80.     nop
  81.                         /* reset context register */
  82.     stba    %g0, [%g4] VMMACH_CONTROL_SPACE
  83.  
  84. /*
  85.  * Force a non-PC-relative jump to the real start of the kernel.
  86.  */
  87.     set    begin, %g1
  88.     jmp    %g1                /* jump to "begin" */
  89.     nop
  90. begin:
  91.     /*
  92.      * Zero out the bss segment.
  93.      */
  94.     set    _edata, %g2
  95.     set    _end, %g3
  96.     cmp    %g2, %g3    /* if _edata == _end, don't zero stuff. */
  97.     be    doneZeroing
  98.     nop
  99.     clr    %g1
  100. zeroing:
  101.     /*
  102.      * Use store doubles for speed.  Both %g0 and %g1 are zeroes.
  103.      */
  104.     std    %g0, [%g2]
  105.     add    %g2, 0x8, %g2
  106.     cmp    %g2, %g3
  107.     bne    zeroing
  108.     nop
  109. doneZeroing:
  110.     /*
  111.      * Now set the stack pointer to my own stack for the first kernel
  112.      * process.  The stack grows towards low memory.  I start it at
  113.      * the beginning of the text segment (CAREFUL: if loading demand-paged,
  114.      * then the beginning of the text segment is 32 bytes before the
  115.      * first code.  Set it really at the beginning of the text segment and
  116.      * not at the beginning of the code.), and it can grow up to
  117.      * MACH_KERN_START.
  118.      *
  119.      * The %fp points to top word on stack of one's caller, so it points
  120.      * to the base of our stack.  %sp points to the top word on the
  121.      * stack for our current stack frame.   This must be set at least
  122.      * to enough room to save our in registers and local registers upon
  123.      * window overflow (and for main to store it's arguments, although it
  124.      * doesn't have any...).
  125.      */
  126.     set    MACH_STACK_START, %fp
  127.     set    (MACH_STACK_START - MACH_FULL_STACK_FRAME), %sp
  128.     andn    %sp, 0x7, %sp            /* double-word aligned */
  129.  
  130.     /*
  131.      * Now set up initial trap table by copying machProtoVectorTable
  132.      * into reserved space at the correct alignment.  The table must
  133.      * be aligned on a MACH_TRAP_ADDR_MASK boundary, and it contains
  134.      * ~MACH_TRAP_ADDR_MASK + 1 bytes.  We copy doubles (8 bytes at
  135.      * a time) for speed.  %g1 is source for copy, %g2 is destination,
  136.      * %g3 is the counter copy, %g4 and %g5 are the registers used for
  137.      * the double-word copy, %l1 is for holding the size of the table,
  138.      * and %l2 contains the number of bytes to copy.  %g6 stores the
  139.      * original destination, so that we can do some further copies, and
  140.      * so that we can put it into the tbr..
  141.      */
  142.     set    machProtoVectorTable, %g1        /* g1 contains src */
  143.     set    reserveSpace, %g2            /* g2 to contain dest */
  144.     set    (1 + ~MACH_TRAP_ADDR_MASK), %l1
  145.     set    ((1 + ~MACH_TRAP_ADDR_MASK) / 8), %l2    /* # bytes to copy */
  146.     add    %g2, %l1, %g2                /* add size of table */
  147.     and    %g2, MACH_TRAP_ADDR_MASK, %g2        /* align to 4k bound. */
  148.     mov    %g2, %g6                /* keep value of dest */
  149.     clr    %g3                    /* clear counter */
  150. copyingTable:
  151.     ldd    [%g1], %g4                /* copy first 2 words */
  152.     std    %g4, [%g2]
  153.     ldd    [%g1 + 8], %g4                /* next 2 words */
  154.     std    %g4, [%g2 + 8]
  155.     add    %g2, 16, %g2                /* incr. destination */
  156.     add    %g3, 2, %g3                /* incr. counter */
  157.     cmp    %g3, %l2                /* how many copies */
  158.     bne    copyingTable
  159.     nop
  160.  
  161.     /*
  162.      * Now copy in the overflow and underflow trap code.  These traps
  163.      * bypass the regular preamble and postamble for speed, and because
  164.      * they are coded so that the only state they need save is the psr.
  165.      * %g6 was the trap table address saved from above.
  166.      */
  167.     set    machProtoWindowOverflow, %g1        /* new src */
  168.     set    MACH_WINDOW_OVERFLOW, %g2        /* get trap offset */
  169.     add    %g6, %g2, %g2                /* offset in table */
  170.     ldd    [%g1], %g4                /* copy first 2 words */
  171.     std    %g4, [%g2]
  172.     ldd    [%g1 + 8], %g4                /* copy next 2 words */
  173.     std    %g4, [%g2 + 8]
  174.  
  175.     set    machProtoWindowUnderflow, %g1        /* new src */
  176.     set    MACH_WINDOW_UNDERFLOW, %g2        /* get trap type */
  177.     add    %g6, %g2, %g2                /* offset in table */
  178.     ldd    [%g1], %g4                /* copy first 2 words */
  179.     std    %g4, [%g2]
  180.     ldd    [%g1 + 8], %g4                /* copy next 2 words */
  181.     std    %g4, [%g2 + 8]
  182.     /*
  183.      * Now copy the handler for non-maskable asynchronous memory error
  184.      * interrupts.  We're going to die anyway on these errors, so all
  185.      * we want to do is grab information and put it into registers.
  186.      */
  187.     set    machProtoLevel15Intr, %g1        /* new src */
  188.     set    MACH_LEVEL15_INT, %g2            /* get trap offset */
  189.     add    %g6, %g2, %g2                /* offset in table */
  190.     ldd    [%g1], %g4                /* copy first 2 words */
  191.     std    %g4, [%g2]
  192.     ldd    [%g1 + 8], %g4                /* copy next 2 words */
  193.     std    %g4, [%g2 + 8]
  194.  
  195.     mov    %g6, %tbr            /* switch in my trap address */
  196.     set    _machTBRAddr, %g2
  197.     st    %g6, [%g2]            /* save tbr addr in C var */
  198.     MACH_WAIT_FOR_STATE_REGISTER()            /* let it settle for
  199.                              * the necessary
  200.                              * amount of time.  Note
  201.                              * that during this
  202.                              * wait period, we
  203.                              * may get an interrupt
  204.                              * to the old tbr if
  205.                              * interrupts are
  206.                              * disabled.  */
  207.     call    _main
  208.     nop
  209.  
  210.     
  211. .align 8
  212. .global    _PrintArg
  213. /*
  214.  * PrintArg:
  215.  *
  216.  * Move integer argument to print into %o0.  This will print
  217.  * desired integer in hex.  This routine uses o0, o1, VOL_TEMP1, and VOL_TEMP2.
  218.  * For the sun4c, it also uses o3.
  219.  */
  220. _PrintArg:
  221.     .seg    "data1"
  222. argString:
  223.     .ascii    "PrintArg: %x\012\0"
  224.     .seg    "text"
  225.  
  226.     mov    %o0, %o1
  227.     set    argString, %o0
  228.     mov    %o7, %VOL_TEMP1
  229. #ifdef sun4c
  230.     sethi   %hi(0xffe80078),%VOL_TEMP2
  231.     ld      [%VOL_TEMP2+%lo(0xffe80078)],%VOL_TEMP2
  232. #else
  233.     sethi   %hi(-0x17ef7c),%VOL_TEMP2
  234.     ld      [%VOL_TEMP2+%lo(-0x17ef7c)],%VOL_TEMP2
  235. #endif
  236.     call    %VOL_TEMP2, 2
  237.     nop
  238.     mov    %VOL_TEMP1, %o7
  239.     retl
  240.     nop
  241.  
  242. .globl    _MachTrap
  243. /*
  244.  * Reserve twice the amount of space we need for the trap table.
  245.  * Then copy machProtoVectorTable into it repeatedly, starting at
  246.  * a 4k-byte alignment.  This is dumb, but the assembler doesn't allow
  247.  * me to do much else.
  248.  *
  249.  * Note that this filler cannot use l1 or l2 since that's where pc and npc
  250.  * are written in a trap.
  251.  */
  252. .align    8
  253. machProtoVectorTable:
  254.     sethi    %hi(_MachTrap), %VOL_TEMP1    /* set _MachTrap, %VOL_TEMP1 */
  255.     or    %VOL_TEMP1, %lo(_MachTrap), %VOL_TEMP1
  256.     jmp    %VOL_TEMP1        /* must use non-pc-relative jump here */
  257.     rd    %psr, %CUR_PSR_REG
  258.  
  259. machProtoWindowOverflow:
  260.     sethi    %hi(MachHandleWindowOverflowTrap), %VOL_TEMP1
  261.     or    %VOL_TEMP1, %lo(MachHandleWindowOverflowTrap), %VOL_TEMP1
  262.     jmp    %VOL_TEMP1
  263.     rd    %psr, %CUR_PSR_REG
  264.  
  265. machProtoWindowUnderflow:
  266.     sethi    %hi(MachHandleWindowUnderflowTrap), %VOL_TEMP1
  267.     or    %VOL_TEMP1, %lo(MachHandleWindowUnderflowTrap), %VOL_TEMP1
  268.     jmp    %VOL_TEMP1
  269.     rd    %psr, %CUR_PSR_REG
  270.  
  271. machProtoLevel15Intr:
  272.     sethi    %hi(MachHandleLevel15Intr), %VOL_TEMP1
  273.     or    %VOL_TEMP1, %lo(MachHandleLevel15Intr), %VOL_TEMP1
  274.     jmp    %VOL_TEMP1
  275.     rd    %psr, %CUR_PSR_REG
  276.  
  277. .align    8
  278. reserveSpace:    .skip    0x2000
  279.